package model
{
	import mx.collections.ArrayCollection;
	import flash.events.EventDispatcher;
		
	public class PlayList extends EventDispatcher
	{
		public var listID:String;
		public var listTitle:String;
		public var loaded:Boolean;
		public var ownerID:int;
		private var _arrSongs:ArrayCollection;
		
		public function PlayList(){
			this._arrSongs = new ArrayCollection();
			this.loaded = false;
			this.ownerID = -1;
		}
		public function clone():PlayList{
			var list:PlayList = new PlayList();
			list.listID = this.listID;
			list.listTitle = this.listTitle;
			list.loaded = this.loaded;
			list.ownerID = this.ownerID;
		
			for(var i:int=0;i<this._arrSongs.length;i++){
				list.append(Song(this._arrSongs[i]).clone());
			}
			return list;
		}
		public function append(song:Song):void{
			this._arrSongs.addItem(song);
		}
		public function remove(song:Song):void{
			//this._arrSongs.remove(song);
			//this._arrSongs.rem
			var idx:int = -1;
			for(var i:int=0;i<this._arrSongs.length;i++){
				if(this._arrSongs[i] == song){
					idx = i;
				}
			}
			if(idx != -1){
				this._arrSongs.removeItemAt(idx);
			}
		}
		public function clear():void{
			this._arrSongs.removeAll();
		}
		/*public function get itemCount():int{
			return this._arrSongs.length;
		}
		public function get items(index:int):Song{
			if(index<0||index>this._arrSongs.length-1){
				throw('Index out of bound');	
			}
			return this._arrSongs[index];
		}*/
		public function get items():ArrayCollection{
			return this._arrSongs;
		}
	}

}